#include <QtGui>
#include "link.h"

#ifndef NODE_H
#define NODE_H

class Node : public QGraphicsItem
{
  Q_DECLARE_TR_FUNCTIONS(Node);

public:
  enum { WIDTH = 50, HEIGHT = 50 };

  Node();
  ~Node();

  void setText(const QString &text);
  QString text()  const { return myText; }
  void setTextColor(const QColor &color);
  QColor textColor() const { return myTextColor; }
  void setOutlineColor(const QColor &color) { myOutlineColor = color; update(); }
  QColor outlineColor() const { return myOutlineColor; }
  void setBackgroundColor(const QColor &color) { myBackgroundColor = color; update(); }
  QColor backgroundColor() const { return myBackgroundColor; }

  void addLink(Link * link);
  void removeLink(Link * link);
  
  QRectF boundingRect() const;
  QPainterPath shape() const;
  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

protected:
  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
  //void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
  void hoverEnterEvent(QGraphicsSceneMouseEvent *event);
  void hoverLeaveEvent(QGraphicsSceneMouseEvent *event);
  QVariant itemChange(GraphicsItemChange change, const QVariant &value);

private:
  QRectF outlineRect() const;
  int roundness(double size) const;
  
  QSet<Link *> myLinks;
  QString myText;
  QColor myTextColor;
  QColor myBackgroundColor;
  QColor myOutlineColor;
};
#endif

